package com.goldplusgold.live;

import android.text.TextUtils;
import android.util.Log;

import com.example.account.manager.AppCacheSharedPreferences;
import com.example.account.manager.ParmasKey;
import com.goldplusgold.live.bean.QuestionBean;
import com.goldplusgold.live.bean.SwitchBean;
import com.goldplusgold.live.result.ResultAnswers;
import com.goldplusgold.live.result.ResultLikes;
import com.goldplusgold.live.result.ResultLivePlayAddress;
import com.goldplusgold.live.result.ResultLiveQuestions;
import com.goldplusgold.live.result.ResultMessages;
import com.goldplusgold.live.result.ResultRecords;
import com.goldplusgold.live.bean.CIntroBean;
import com.goldplusgold.live.bean.LDetailBean;
import com.goldplusgold.live.bean.VDetailBean;
import com.goldplusgold.live.result.ResultColumns;
import com.goldplusgold.live.result.ResultLives;
import com.goldplusgold.live.result.ResultUserQuestions;
import com.goldplusgold.live.result.ResultVideoAnswers;
import com.goldplusgold.live.result.ResultVideoQuestions;
import com.goldplusgold.live.result.ResultVideos;
import com.goldplusgold.network.lib.http.BaseRetrofit;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;

/**
 * Created by Administrator on 2017/7/10.
 */

public class LVDataManager {

    private static LVDataManager homeManager;
    public static final int PAGE_COUNT = 10;
    public static List<Callback> callbacks ;

    private LVDataManager(){
    }

    public static LVDataManager getInstance(){
        if(homeManager == null){
            synchronized (LVDataManager.class){
                if(homeManager == null){
                    homeManager = new LVDataManager();

                    callbacks = new ArrayList<Callback>();
                }
            }
        }
        return homeManager;
    }

    public void getColumns(){
        LVideoService service = BaseRetrofit.getInstance().create(LVideoService.class);
        Call<ResultColumns> call = service.getColumns();
        call.enqueue(new Callback<ResultColumns>() {
            @Override
            public void onResponse(Call<ResultColumns> call, retrofit2.Response<ResultColumns> response) {
            }

            @Override
            public void onFailure(Call<ResultColumns> call, Throwable t) {
            }
        });
    }

    public Call getLives(int offset, int count, Callback callback){
        LVideoService service = BaseRetrofit.getInstance().create(LVideoService.class);
        Call<ResultLives> call = service.getLives(offset,count);
        call.enqueue(callback);
        return call ;
    }

    public Call getVideos(int offset, int count,Callback callback){
        LVideoService service = BaseRetrofit.getInstance().create(LVideoService.class);
        Call<ResultVideos> call = service.getVideos(offset,count);
        call.enqueue(callback);
        return call;
    }


    public Call getVDetail(String videoID,Callback callback){
        Call<VDetailBean> call = null;
        if(!TextUtils.isEmpty(videoID)){
            LVideoService service = BaseRetrofit.getInstance().create(LVideoService.class);
            call = service.getVDetail(videoID);
            call.enqueue(callback);
        }
        return  call ;
    }

    public void getLDetail(String liveID,Callback callback){
        if(!TextUtils.isEmpty(liveID)){
            LVideoService service = BaseRetrofit.getInstance().create(LVideoService.class);
            Call<LDetailBean> call = service.getLDetail(liveID, AppCacheSharedPreferences.getCacheString(ParmasKey.token));
            call.enqueue(callback);
        }
    }

    public void getRecords(String columnId,int offset, int count,Callback callback){
        if(!TextUtils.isEmpty(columnId)){
            LVideoService service = BaseRetrofit.getInstance().create(LVideoService.class);
            Call<ResultRecords> call = service.getRecords(columnId,offset,count);
            call.enqueue(callback);
        }
    }

    public Call getColumns(final Callback callback){
        LVideoService service = BaseRetrofit.getInstance().create(LVideoService.class);
        Call<ResultColumns> call = service.getColumns();
        call.enqueue(callback);
        return call ;
    }

    public void getIntro(int count,String columnID,final Callback callback){
        LVideoService service = BaseRetrofit.getInstance().create(LVideoService.class);
        Call<CIntroBean> call = service.getIntro(count,columnID , AppCacheSharedPreferences.getCacheString(ParmasKey.token));
        call.enqueue(callback);
    }

    public void getHistoryMessages(String roomID,String time ,int count,final Callback callback){
        LVideoService service = BaseRetrofit.getInstance().create(LVideoService.class);
        Call<ResultMessages> call = service.getHistoryMessages( roomID, time,count);
        call.enqueue(callback);
    }

    public void getLiveAnswers(String liveID,int offset,int count,final Callback callback){
        LVideoService service = BaseRetrofit.getInstance().create(LVideoService.class);
        Call<ResultAnswers> call = service.getLiveAnswers(liveID,offset,count);
        call.enqueue(callback);
    }

    public void getLiveQuestions(String liveID,int offset,int count,final Callback callback){
        LVideoService service = BaseRetrofit.getInstance().create(LVideoService.class);
        Call<ResultLiveQuestions> call = service.getLiveQuestions(liveID,offset,count, AppCacheSharedPreferences.getCacheString(ParmasKey.token));
        call.enqueue(callback);
    }

    public void putLiveQuestion(String liveID,String content,final Callback callback){
        LVideoService service = BaseRetrofit.getInstance().create(LVideoService.class);
        Call<QuestionBean> call = service.putLiveQuestion(liveID,content, AppCacheSharedPreferences.getCacheString(ParmasKey.token));
        Log.e("token" , AppCacheSharedPreferences.getCacheString(ParmasKey.token) );
        call.enqueue(callback);
    }

    public void putVideoQuestion(String liveID,String content,final Callback callback){
        LVideoService service = BaseRetrofit.getInstance().create(LVideoService.class);
        Call<QuestionBean> call = service.putVideoQuestion(liveID,content, AppCacheSharedPreferences.getCacheString(ParmasKey.token));
        call.enqueue(callback);
    }

    public void follow(String columnID,final Callback callback){
        LVideoService service = BaseRetrofit.getInstance().create(LVideoService.class);
        Call<QuestionBean> call = service.follow(columnID,AppCacheSharedPreferences.getCacheString(ParmasKey.token));
        call.enqueue(callback);
    }

    public void unFollow(String columnID,final Callback callback){
        LVideoService service = BaseRetrofit.getInstance().create(LVideoService.class);
        Call<QuestionBean> call = service.unFollow(columnID, AppCacheSharedPreferences.getCacheString(ParmasKey.token));
        call.enqueue(callback);
    }

    public void getVideoAnswers(String videoID,int offset,int count,final Callback callback){
        LVideoService service = BaseRetrofit.getInstance().create(LVideoService.class);
        Call<ResultVideoAnswers> call = service.getVideoAnswers(videoID,offset,count);
        call.enqueue(callback);
    }

    public void getVideoQuestions(String videoID,int offset,int count,final Callback callback){
        LVideoService service = BaseRetrofit.getInstance().create(LVideoService.class);
        Call<ResultVideoQuestions> call = service.getVideoQuestions(videoID,offset,count, AppCacheSharedPreferences.getCacheString(ParmasKey.token));
        call.enqueue(callback);
    }

    public void getFollows(final Callback callback){
        LVideoService service = BaseRetrofit.getInstance().create(LVideoService.class);
        Call<ResultLikes> call = service.getLikes(AppCacheSharedPreferences.getCacheString(ParmasKey.token));
        call.enqueue(callback);
    }

    public void getUserQuestions(int offset,int count,final Callback callback){
        LVideoService service = BaseRetrofit.getInstance().create(LVideoService.class);
        Call<ResultUserQuestions> call = service.getUserQuestions(offset,count, AppCacheSharedPreferences.getCacheString(ParmasKey.token));
        call.enqueue(callback);
    }

    public void getSwitch(Callback callback){
        LVideoService service = BaseRetrofit.getInstance().create(LVideoService.class);
        Call<SwitchBean> call = service.getSwitch();
        call.enqueue(callback);
    }

    public void getLivePlayAddress(String liveID , Callback callback){
        LVideoService service = BaseRetrofit.getInstance().create(LVideoService.class);
        Call<ResultLivePlayAddress> call = service.getLivePlayAddress(liveID);
        call.enqueue(callback);
    }
}
